import axios from 'axios';
import { downloadFileTemplate } from '../utils/files';
import type { IQuery, IResponse, TableResponse } from '@/api/config/types';

export interface IResolution {
  resolutionId: string;
  width: number;
  height: number;
  description: any;
  dpi: number;
  scale: number;
  code: string;
  toRotate: '1' | '0';
  mode: string;
  color: string;
}

const prefix = '/resolution/resolution';

export const queryResolution = () => {
  return axios.get<IResponse<IResolution[]>>(`${prefix}/query`);
};

// 查询分辨率列表
export const listResolution = (query?: IQuery) => {
  return axios.get<TableResponse<IResolution>>(`${prefix}/list`, { params: query });
};
export const getResolution = (id: string | number) => {
  return axios.get<IResponse<IResolution>>(`${prefix}/${id}`);
};

// 删除分辨率
export const delResolution = (resolutionId: Array<string>) => {
  return axios.delete(`${prefix}/${resolutionId.join(',')}`);
};

// 新增分辨率
export const addResolution = (data: IResolution) => {
  return axios.post(`${prefix}`, data);
};

// 修改分辨率
export const updateResolution = (data: IResolution) => {
  return axios.put(`${prefix}`, data);
};

// 导出代码
type ExportCodeParam = {
  model: string;
  count: number;
};

export const exportCode = (params: ExportCodeParam) => {
  return downloadFileTemplate('/v2/sys/api/auto/id', params);
};
